<template>
  <!-- 全部小说-小说书库 -->
  <div id="main">
    <div id="hotcontent">
      <div class="lll">
        <h2>书荒网小说大全</h2>
        <!-- 书库小说数据列表  table -->
        <el-table
          :data="librarylist"
          border
          stripe
          :header-cell-style="{ textAlign: 'center' }"
          :cell-style="{ textAlign: 'center' }"
        >
          <el-table-column type="index" label="ID"></el-table-column>
          <el-table-column label="类别" prop="book_cate" width="100">
            <template slot-scope="scope">
              <div
                @click="JumpCatesRoute(scope.row.book_cate)"
                style="cursor:pointer"
              >
                [{{ scope.row.book_cate }}小说]
              </div>
            </template>
          </el-table-column>
          <el-table-column label="书名" prop="book_name" width="300">
            <template slot-scope="scope">
              <div
                @click="JumpDetailRoute(scope.row.book_id)"
                style="cursor:pointer"
              >
                {{ scope.row.book_name }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="最新章节" prop="book_newest_name" width="300">
            <template slot-scope="scope">
              <div
                @click="
                  JumpChapterRoute(scope.row.book_id, scope.row.book_newest_url)
                "
                style="cursor:pointer"
              >
                {{ scope.row.book_newest_name }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="书籍情况" prop="book_status" width="120">
            <template slot-scope="scope">
              <el-tag type="success" v-if="scope.row.book_status === '连载中'"
                >连载中</el-tag
              >
              <el-tag type="warning" v-else>完本</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="作者" prop="book_author"></el-table-column>
        </el-table>
      </div>
      <div class="pages">
        <!-- 分页区域 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[15, 30, 45, 90]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import '../../assets/css/library.css'
export default {
  data() {
    return {
      // 请求查询参数对象
      queryInfo: {
        pagenum: 1, // 当前页数
        pagesize: 30 // 每页条数
      },
      // 书库数据列表
      librarylist: [],
      // 总数据条数
      total: 0
    }
  },
  created() {
    //   获取书库列表数据
    this.getLibrarylist()
  },
  methods: {
    // 点击事件，跳转小说详情页
    JumpDetailRoute(book_id) {
      this.$router.push({
        path: '/book/' + book_id
      })
    },
    // 点击事件跳转分类小说
    JumpCatesRoute(url) {
      this.$router.push({
        path: this.$store.state.fiction_cate[url]
      })
    },
    // 点击事件，跳转小说章节页
    JumpChapterRoute(book_id, sort_id) {
      this.$router.push({
        path: '/chapter/' + book_id + '/' + sort_id
      })
    },
    // 获取书库列表数据
    async getLibrarylist() {
      const { data: res } = await this.$http.get(`get_library_pages`, {
        params: this.queryInfo
      })

      if (res.status !== 200) {
        return this.$message.error('获取书库分页数据失败！')
      }

      this.librarylist = res.data
      this.total = res.total
      console.log(this.librarylist)
    },
    // 监控当前每页条数
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getLibrarylist()
    },
    // 监控 每页页码值
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage
      this.getLibrarylist()
    }
  }
}
</script>

<style lang="less" scoped>
.el-table,
 .el-table__expanded-cell {
  background-color: #e9faff !important;
}
</style>
